package com.sohh.demo;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

/**
 * @description: some desc
 * @author: ruoan
 * @date: 2021/2/21 15:57
 */
public class Test2 {

    public static void main(String[] args) {

        int i = 0 ;
        try {
            while (i==0) {
                i++;
                Enhancer enhancer = new Enhancer();
                enhancer.setSuperclass(OOMTest.class);
                enhancer.setUseCache(false);
                enhancer.setCallback(new MethodInterceptor() {
                    @Override
                    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {

                        System.out.println(o);
                        System.out.println(method);
                        System.out.println(objects);
                        return methodProxy.invokeSuper(o,args);
                    }
                });
                OOMTest t = (OOMTest) enhancer.create();
                byte[] bytes = t.getBytes();
            }
        } catch (Throwable e) {
            System.out.println("第多少次发生了异常: "+i);
            e.printStackTrace();
        } finally{

        }


    }
}
